"""
Case Type   : USTORE
Case Name   : 验证参数undo_retention_time的异常值
Create At   : 2025/3/12
Owner       : wan005
Description :
    1.修改undo_retention_time值为259200
    2.修改undo_retention_time值为-1和259201、字母
Expect      :
    1.修改成功
    2.修改失败
History     :
"""
import os
import unittest
import sys
from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Logger import Logger
from testcase.utils.Constant import Constant


class Security(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f'---{os.path.basename(__file__)} start---')
        self.sh_primy = CommonSH('PrimaryDbUser')
        self.constant = Constant()
        self.common = Common()

    def test_ustore(self):
        text = '----step1:修改undo_retention_time值为259200;expect:成功----'
        self.logger.info(text)
        self.sh_primy.execute_gsguc('reload',
            self.constant.GSGUC_SUCCESS_MSG, 'undo_retention_time=259200')
        res1_1 = self.common.show_param('undo_retention_time')
        self.assertEqual('3d', res1_1, text + '执行失败')

        text = '----step2:修改undo_retention_time值-1和259201、字母;expect:失败----'
        self.logger.info(text)
        err_msg1 = 'The value -1 is outside the valid range for parameter ' \
                   '"undo_retention_time" (0 .. 259200)'
        res2_1 = self.sh_primy.execute_gsguc('reload', err_msg1,
                                    'undo_retention_time=-1')
        self.assertEqual(True, res2_1, text + '执行失败')
        err_msg2 = 'The value 259201 is outside the valid range for parameter' \
                   ' "undo_retention_time" (0 .. 259200)'
        res2_2 = self.sh_primy.execute_gsguc('reload', err_msg2,
                                    'undo_retention_time=259201')
        self.assertEqual(True, res2_2, text + '执行失败')
        err_msg3 = 'The parameter "undo_retention_time" requires' \
                   ' an integer value'
        res2_3 = self.sh_primy.execute_gsguc('reload', err_msg3,
                                    'undo_retention_time=abc')
        self.assertEqual(True, res2_3, text + '执行失败')

    def tearDown(self):
        text = '-----step1:清理环境，恢复配置;expect:成功-----'
        self.logger.info(text)
        self.sh_primy.execute_gsguc('reload', self.constant.GSGUC_SUCCESS_MSG,
                                    'undo_retention_time=0')
        res2 = self.common.show_param('undo_retention_time')
        self.assertEqual('0', res2, text + '执行失败')
        self.logger.info(f'---{os.path.basename(__file__)} end---')
